package com.fortune.controller;

import com.fortune.base.BaseAPIExcution;
import com.fortune.common.paging.PagingData;
import com.fortune.constants.Constants;
import com.fortune.dto.excution.DealerStatisticsExcution;
import com.fortune.dto.in.ddataAnalysisDto.DorderSummaryDto;
import com.fortune.dto.in.dealerStatistics.DriverOrderDto;
import com.fortune.entity.DUserInfo;
import com.fortune.enums.DealerStatisticsEnum;
import com.fortune.service.DealerStatisticsService;
import com.fortune.vo.ddateAnalysis.ClientPro;
import com.fortune.vo.dealerStatistics.DriverOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Administrator on 2018/7/16 0016.
 */

@Api(value = "dealerStatistics", description = "经销商客户/司机统计", tags = {"经销商客户/司机统计"})
@RestController
@RequestMapping("dealerStatistics")
public class DealerStatisticsController {
    @Autowired
    private DealerStatisticsService dealerStatisticsService;

    @ApiOperation(value = "司机订货统计", nickname = "driverOrderList", notes = "", tags={ "@安童" })
    @ApiImplicitParams({
            @ApiImplicitParam(name="page", value="第几页",paramType="query",dataType="int"),
            @ApiImplicitParam(name="length", value="每页容量",paramType="query",dataType="int"),
            @ApiImplicitParam(name="search", value="搜索",paramType="query",dataType="string"),
            @ApiImplicitParam(name="startTime", value="开始时间",paramType="query",dataType="date"),
            @ApiImplicitParam(name="endTime", value="结束时间",paramType="query",dataType="date"),
    })
    @GetMapping(value = "driverOrderList",
            produces = { MediaType.APPLICATION_JSON_VALUE })
    public BaseAPIExcution<PagingData<DriverOrder>> driverOrderList(HttpServletRequest request, @ApiIgnore @Validated DriverOrderDto driverOrderDto) {
        HttpSession session = request.getSession();
        DUserInfo dUserInfo = (DUserInfo) session.getAttribute(Constants.SESSION_D_USER);
        String dealerId = dUserInfo.getdId();
        driverOrderDto.setPage((driverOrderDto.getPage()-1)*10);
        List<DriverOrder> list = dealerStatisticsService.findDriverOrderList(dealerId,driverOrderDto);
        int count = list.size();
        PagingData<DriverOrder> pagingData = new PagingData<>();
        pagingData.setData(list);
        pagingData.setRecordsTotal(count);
        return new DealerStatisticsExcution<PagingData<DriverOrder>>(pagingData, DealerStatisticsEnum.SUCCESS);
    }

    @ApiOperation(value = "商品销售汇总", nickname = "merchandisingList", notes = "", tags={ "@安童" })
    @ApiImplicitParams({
            @ApiImplicitParam(name="page", value="第几页",paramType="query",dataType="int"),
            @ApiImplicitParam(name="length", value="每页容量",paramType="query",dataType="int"),
            @ApiImplicitParam(name="startTime", value="开始时间",paramType="query",dataType="date"),
            @ApiImplicitParam(name="endTime", value="结束时间",paramType="query",dataType="date"),
    })
    @GetMapping(value = "merchandisingList",
            produces = { MediaType.APPLICATION_JSON_VALUE })
    public BaseAPIExcution<PagingData<DriverOrder>> merchandisingList(HttpServletRequest request, @ApiIgnore @Validated DriverOrderDto driverOrderDto) {
        HttpSession session = request.getSession();
        DUserInfo dUserInfo = (DUserInfo) session.getAttribute(Constants.SESSION_D_USER);
        String dealerId = dUserInfo.getdId();
        driverOrderDto.setPage((driverOrderDto.getPage()-1)*10);
        List<DriverOrder> list = dealerStatisticsService.findMerchandisingList(dealerId,driverOrderDto);
        int count = dealerStatisticsService.findMerchandisingListCount(dealerId,driverOrderDto);
        PagingData<DriverOrder> pagingData = new PagingData<>();
        pagingData.setData(list);
        pagingData.setRecordsTotal(count);
        return new DealerStatisticsExcution<PagingData<DriverOrder>>(pagingData, DealerStatisticsEnum.SUCCESS);
    }

    @ApiOperation(value = "客户订货统计", nickname = "customerOrderList", notes = "", tags={ "@安童" })
    @ApiImplicitParams({
            @ApiImplicitParam(name="page", value="第几页",paramType="query",dataType="int"),
            @ApiImplicitParam(name="length", value="每页容量",paramType="query",dataType="int"),
            @ApiImplicitParam(name="startTime", value="开始时间",paramType="query",dataType="date"),
            @ApiImplicitParam(name="endTime", value="结束时间",paramType="query",dataType="date"),
    })
    @GetMapping(value = "customerOrderList",
            produces = { MediaType.APPLICATION_JSON_VALUE })
    public BaseAPIExcution<PagingData<ClientPro>> customerOrderList(HttpServletRequest request, @ApiIgnore @Validated DorderSummaryDto dorderSummaryDto) {
        HttpSession session = request.getSession();
        DUserInfo dUserInfo = (DUserInfo) session.getAttribute(Constants.SESSION_D_USER);
        String dealerId = dUserInfo.getdId();
        dorderSummaryDto.setPage((dorderSummaryDto.getPage()-1)*10);
        List<ClientPro> list = dealerStatisticsService.findOrderSummaryList(dorderSummaryDto,dealerId);
        int count = dealerStatisticsService.findOrderSummaryListCount(dealerId);
        PagingData<ClientPro> pagingData = new PagingData<>();
        pagingData.setData(list);
        pagingData.setRecordsTotal(count);
        return new DealerStatisticsExcution<PagingData<ClientPro>>(pagingData, DealerStatisticsEnum.SUCCESS);
    }
}
